#!/usr/bin/env bash
# https://cirosantilli.com/linux-kernel-module-cheat#bisection
set -eu
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
"${root_dir}/build-gem5" --arch aarch64 --gem5-worktree bisect --clean || exit 255
"${root_dir}/build-gem5" --arch aarch64 --gem5-worktree bisect || exit 255
set +e
# Setup for quick failures:
# https://stackoverflow.com/questions/4713088/how-to-use-git-bisect/22592593#22592593
timeout 5 "${root_dir}/run" --emulator gem5 --gem5-worktree bisect --quit-after-boot "$@"
if [ $? -ne 124 ]; then
  exit 1
fi
